package org.xinjiang.data.migration.common.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @BelongsProject: swagger
 */
@Configuration
@EnableOpenApi
public class SwaggerUIConfig {

    @Value("${swagger.enable}")
    private boolean enable;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.xinjiang.data.migration"))
                .paths(PathSelectors.any())
                .build().groupName("新疆")
                .enable(enable);
    }

    /**
     * 生成文档
     *
     * @return http://localhost:8244/xinjiang-table-data-migration/swagger-ui/index.html
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger3接口文档")
                .description("新疆数据割接")
                .version("1.0.0")
                .build();
    }
}
